package com.chucang.shucang.bac.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chucang.shucang.bac.entity.AppNoticeEntity;
import com.chucang.shucang.bac.service.AppNoticeService;
import com.chucang.shucang.bac.vo.AppNoticeResVO;
import com.chucang.shucang.common.base.utils.R;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * app公告消息
 *
 * @author flitsneak flitsneak@gmail.com
 * @since 1.0.0 2022-09-11
 */
@RestController
@RequestMapping("/appnotice")
@RequiredArgsConstructor
@Api(tags = "app公告消息")
public class AppNoticeController {

    private final AppNoticeService appNoticeService;

    /**
     * 查询公告列表
     *
     * @return r
     */
    @GetMapping("/listNotices")
    public R<List<AppNoticeResVO>> listNotices() {
        LambdaQueryWrapper<AppNoticeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .orderByDesc(AppNoticeEntity::getCreateTime)
                .select();
        List<AppNoticeEntity> list = appNoticeService.list(lambdaQueryWrapper);
        List<AppNoticeResVO> appNoticeResVOS = BeanUtil.copyToList(list, AppNoticeResVO.class);
        return R.ok(appNoticeResVOS);
    }
}